<template>
    <div class="swiper mySwiper">
        <div class="swiper-wrapper">
            <div class="swiper-slide" v-for="item in bannerList">
                <img :src="item.imgUrl" alt="">
            </div>
        </div>
        <div class="swiper-pagination"></div>
        <div class="swiper-button-next"></div>
        <div class="swiper-button-prev"></div>
    </div>
</template>

<script>
import Swiper from '../../../../public/tools/swiper-bundle.min.js'
import axios from 'axios'
export default {
    data() {
        return {
            bannerList:[]
        }
    },
    mounted() {
        axios.get('https://apipc-xiaotuxian-front.itheima.net/home/banner').then((res)=>{
            if(res.data.msg == '操作成功'){
                this.bannerList = res.data.result  // 数据到了但是dom没有更新
                // console.log(document.querySelectorAll('.swiper-slide'));  // NodeList []
                // 数据到了指定位置
                this.$nextTick(()=>{
                    this.swiperLoop()
                    // console.log(document.querySelectorAll('.swiper-slide')); 
                })
            }
        })
    },
    methods: {
        swiperLoop() {
            var mySwiper = new Swiper(".mySwiper", {
            pagination: {
                el: ".swiper-pagination",
            },
            navigation: {
                nextEl: ".swiper-button-next",
                prevEl: ".swiper-button-prev",
            },
            speed: 1300,
            loop: true,
            autoplay: {
                delay: 1000
            },
            // autoplay: true
        });

        //鼠标覆盖停止自动切换
        mySwiper.el.onmouseover = function () {
            mySwiper.autoplay.stop();
        }

        //鼠标离开开始自动切换
        mySwiper.el.onmouseout = function () {
            mySwiper.autoplay.start();
        }
        }
    },
}
</script>

<style lang="scss" scoped>
@import url('../../../../public/tools/swiper-bundle.min.css');

html,
body {
    position: relative;
    height: 100%;
}

body {
    background: #eee;
    font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
    font-size: 14px;
    color: #000;
    margin: 0;
    padding: 0;
}

.swiper {
    width: 100%;
    height: 100%;
}

.swiper-slide {
    text-align: center;
    font-size: 18px;
    background: #fff;

    /* Center slide text vertically */
    display: -webkit-box;
    display: -ms-flexbox;
    display: -webkit-flex;
    display: flex;
    -webkit-box-pack: center;
    -ms-flex-pack: center;
    -webkit-justify-content: center;
    justify-content: center;
    -webkit-box-align: center;
    -ms-flex-align: center;
    -webkit-align-items: center;
    align-items: center;
}

.swiper-slide img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

// scss ::v-deep 样式穿透，突破scoped的限制，修改其他元素的样式
// css 选择器 >>> 选择器
// 默认小圆点
::v-deep .swiper-pagination-bullet {
    width:12px;
    height: 12px;
}


// active小圆点
::v-deep .swiper-pagination-bullet-active {
    background: #fff ;
}
.swiper-button-prev {
    left: 280px
}
</style>